package com.briup.cms.web.controller;

import com.briup.cms.bean.Category;
import com.briup.cms.service.ICategoryService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: thh
 * @Date: 2021/7/17
 * @Time: 19:17
 * @Description:
 */
@RestController
@Api(tags = "资讯栏目相关接口")
@RequestMapping("/auth/category")
public class CategoryController {
    @Autowired
    private ICategoryService service;

    @ApiOperation("分页查询")
    @GetMapping("/page/queryAll")
    public Message pageAll(int pageNum,int pageSize){
        PageInfo<Category> data = service.pageAll(pageNum, pageSize);
        return MessageUtil.success(data);

    }

    @ApiOperation("批量删除")
    @DeleteMapping({"/batchDelete"})
    public Message batchDelete(int[] ids) {

        service.batchdelete(ids);
        return MessageUtil.success(ids);
    }

    @ApiOperation("保存所有信息")
    @PostMapping("/save")
    public Message insert(Category record){
        service.insert(record);
        return MessageUtil.success(record);
    }
    @ApiOperation("改变所有信息")
    @PutMapping("/update")
    public Message update(Category record){
        service.updateByPrimaryKey(record);
        return MessageUtil.success(record);
    }
    @ApiOperation("根据id删除栏目信息")
    @DeleteMapping("/deleteById")
    public Message deleteByPrimaryKey(Integer id){
        service.deleteByPrimaryKey(id);
        return  MessageUtil.success(id);
    }
    @ApiOperation("查询所有栏目")
    @GetMapping("/find/all")
    public Message findall(){
        List<Category> findall =service.findall();
        return MessageUtil.success(findall);

    }



}
